function CocosMagicObject(file,callback) {

    this.$content = null;
    this.$parseSouce = null;
    this.$cocosNode = null;

    var _this = this;
    console.log(file)
    cc.loader.loadTxt(file, function(err, data){
        if(err) return console.log("load failed");
        //success
        _this.$content = data;
        _this.parse();
        console.log(data)

    });

    if(callback){
        this.$callback = callback;
    }
}

CocosMagicObject.prototype.parse = function () {
    var json = himalaya.parse(this.$content);
    this.$parseSouce = json;
    this.build();
    // console.log('👉', json)
}


CocosMagicObject.prototype.build = function () {
    //从0号开始
    if(!this.$parseSouce.length){
        return;
    }
    var node = this.buildItem(this.$parseSouce[0]);
    if(node){
        this.$cocosNode = node;
        if(this.$callback){
            this.$callback.call(this);
        }
    }
}

CocosMagicObject.prototype.buildItem = function (item) {
    if(item.type === 'Text') return null;
    var box = null;

    if(!CocosMagic.components[item.tagName]){
        return null;
    }

    box = CocosMagic.components[item.tagName].nodeBuilder.call(this);

    //element
    // switch (item.tagName){
    //     case 'panel':
    //         box = new ccui.Layout();
    //         break;
    //
    //     case 'text':
    //         box = new ccui.Text();
    //         break;
    //
    // }

    if(!box){
        return null;
    }

    //attributes
    this.buildCommonAttributes(box,item.attributes);

    if(CocosMagic.components[item.tagName].attributesBuilder){
        CocosMagic.components[item.tagName].attributesBuilder.call(this,box,item.attributes);
    }

    //build child
    this.buildChildren(box,item.children);

    return box;

};

CocosMagicObject.prototype.buildCommonAttributes = function (item,attributes) {
    for(var attrName in attributes){
        var val = attributes[attrName];
        switch (attrName){
            case 'x':
                item.x = val;
                break;

            case 'y':
                item.y = val;
                break;

        }
    }
}

CocosMagicObject.prototype.buildChildren = function (item,children) {
    if(children && children.length){
        var _this = this;
        children.forEach(function (child) {
            var childNode = _this.buildItem(child);
            if(childNode == null){
                return;
            }
            item.addChild(childNode);
        })
    }
};